﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BLL;
using DAL;

namespace QLTTTH
{
    public partial class frmThongTinThietBi : DevExpress.XtraEditors.XtraForm
    {
        public frmThongTinThietBi()
        {
            InitializeComponent();
        }
        public void FillControl(ThietBi tb)
        {
            this.txtMaTB.Text = tb.MaTB.ToString();
            this.txtTenTB.Text = tb.TenTB;
            this.txtChucNang.Text = tb.ChucNang;
            this.txtTrangThai.Text = tb.TrangThai;
            this.txtMaPhong.Text = tb.MaPhong.ToString();
        }
        public void BatNutLuu()
        {
            this.btnLuu.Enabled = true;
        }

        private void btnHuyBo_Click(object sender, EventArgs e)
        {
            ResetControl();
            this.Close();
        }
        private void ResetControl()
        {
            this.txtMaTB.ResetText();
            this.txtTenTB.ResetText();
            this.txtChucNang.ResetText();
            this.txtTrangThai.ResetText();
            this.txtMaPhong.ResetText();
        }
        public delegate void SendData(ThietBi tb);

        public SendData sendData;

        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (sendData != null)
            {
                var vResult = new ThietBiManager().Validate(GetThietBi());
                if (vResult.Valid)
                {
                    sendData(GetThietBi());
                    DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    XtraMessageBox.Show(vResult.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public ThietBi GetThietBi()
        {
            ThietBi tb = new ThietBi();
            if (!txtMaTB.Text.ToString().Equals(""))
            {
                tb.MaTB = int.Parse(txtMaTB.Text.ToString());
            }
            tb.TenTB = txtTenTB.Text;
            tb.ChucNang = txtChucNang.Text;
            tb.TrangThai = txtTrangThai.Text;
            tb.MaPhong = int.Parse(txtMaPhong.Text.ToString());
            return tb;
        }
    }
}